package com.sss.demo.web.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sss.demo.GlobalConstants;
import com.sss.demo.db.pojo.MyUserVo;
import com.sss.demo.db.pojo.UserVo;
import com.sss.demo.web.BaseController;
import com.sss.demo.web.methodLog;

@Controller
@RequestMapping(value="home")
public class HomeController extends BaseController{
	
	@RequestMapping(value="/user",method=RequestMethod.GET)
	@methodLog(operateDesc="request home/user",operateType="requestURL")
	public String toUserPage(HttpServletRequest request){
		logInfo("info message request /home/user");
		logErr("info message request /home/user");
		logWarn("info message request /home/user");
		UserVo user=new UserVo();
		user.setMail("Tommy@sina.com");
		user.setName("Tommy");
		request.getSession().setAttribute(GlobalConstants.SESSION_ACTOR_KEY, user);
		return "userPage";
	}
	
	@RequestMapping(value="/userContainer",method=RequestMethod.GET)
	@methodLog(operateDesc="request home/userContainer",operateType="requestURL")
	public String toUserContainer(HttpServletRequest request){
		logInfo("info message request /home/userContainer");
		logErr("info message request /home/userContainer");
		logWarn("info message request /home/userContainer");
		UserVo user=new UserVo();
		user.setMail("Tommy@sina.com");
		user.setName("Tommy");
		request.getSession().setAttribute(GlobalConstants.SESSION_ACTOR_KEY, user);
		request.setAttribute("panelModule", "userPanel");
		return "userContainerPage";
	}
	
	@RequestMapping(value="/jsonint",method=RequestMethod.GET)
	@ResponseBody
	public int getJsonInt(){
		return 2;
	}
	
	@RequestMapping(value="/jsonString",method=RequestMethod.GET)
	@ResponseBody
	public String getJsonString(){
		return "str";
	}
	
	@RequestMapping(value="/jsonMap",method=RequestMethod.GET)
	@ResponseBody
	public Map<String,String> getJsonMap(){
		Map<String ,String> map=new HashMap<String,String>();
		map.put("name", "zhaoqiang");
		map.put("company", "Spring Airlines");
		return map;
	}
	
	@RequestMapping(value="/jsonObject",method=RequestMethod.GET)
	@ResponseBody
	public Object getJsonObject(){
		
		return new MyUserVo(20, "Zhao Qiang", new Integer(5), new Date(System.currentTimeMillis()));
	}
	
	@RequestMapping(value="/userData",method=RequestMethod.GET)
	@methodLog(operateDesc="request home/userData",operateType="jquery ajax get")
	@ResponseBody
	public String userData(@RequestParam("name")String name){
		return "jquery ajax name: "+name;
		
	}
	
}
